<?php
require_once $_SERVER["DOCUMENT_ROOT"] . "/config/globalconfig.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/public/News.php";
$news = new News();
$news->loginCheck();
$action = $_REQUEST["action"];
$condition = array();
//$data = array();
$reda;
$message = "success";
$code = 200;
try {
    switch ($action) {
        case LOAD:
            $reda = $news->findOne();
            break;
        case LOAD_ID:
            $condition[$news->getPrimaryKey()] = $_GET["id"];
            $reda = $news->findOne($condition);
            break;
        case UPLOAD:
            echo "upload";
            break;
        case ALL:
            $reda = $news->findList();
            break;
        case PAGE:
            $page = $_REQUEST["currentPage"];
            $pageSize = $_REQUEST["pageSize"];
            $condition = $news->searchData();
            $reda = $news->findByPage($page, $pageSize, $condition);
            break;
        case DELETE:
            $ids = $_POST["ids"];
            $condition[$news->getPrimaryKey()] = [$news->param_operation => "in", $news->param_value_key => $ids];
            $reda = $news->delete($condition);
            break;
        case MERGE:
            $data = $news->parseRequestData();
            $reda = $news->merge($news->getPrimaryKey(), $data);
            break;
        default:
            $reda = "未知Action";
    }
    $news->result($reda, $message, $code);
} catch (Exception $e) {
    $news->result($e->getMessage(), $news->error_msg, $news->error_code);
}


?>
